package com.jiashihui.server1.utils;

import java.util.Random;
import java.util.UUID;

/**
*describe: UUID
*
*@author jiashihui
*@date 2018/11/30
*/
public class UUIDUtil {

	private static Random random = new Random();

	/**
	 * @description 获取UUID
	 * @date: 2018/11/30 13:41
	 * @author: jiashihui
	 * @return 
	 */
	public static String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}

	/**
	 * @description 获得指定数量的UUID
	 * @date: 2018/11/30 13:41
	 * @author: jiashihui
	 * @param number
	 * @return 
	 */
	public static String[] getUUID (int number) {
		if (number < 1) {
			return null;
		}
		String[] result = new String[number];
		for (int i = 0; i < number; i++) {
			result[i] = getUUID();
		}
		return result;
	}

	/**
	 * @author: jiashihui
	 * @description 描述一下方法的作用
	 * @date: 2018/11/30 14:34
	 * @param number
	 * @return 
	 */
	public static String getRandomString(int number) {
		StringBuilder result = new StringBuilder();
		char[] strs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z' };
		for (int i = 0; i < number; i++) {
			result.append(strs[random.nextInt(strs.length)]);
		}
		return result.toString();
	}

	/**
	 * @author: jiashihui
	 * @description 描述一下方法的作用
	 * @date: 2018/11/30 14:35
	 * @param number
	 * @return 
	 */
	public static String getRandomLowString(int number) {
		StringBuilder result = new StringBuilder();
		char[] strs = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
				'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n',
				'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
		for (int i = 0; i < number; i++) {
			result.append(strs[random.nextInt(strs.length)]);
		}
		return result.toString();
	}

	/**
	 * @author: jiashihui
	 * @description 获取16进制随机数
	 * @date: 2018/11/30 14:36
	 * @param len
	 * @return 
	 */
    public static String randomHexString(int len) throws Exception {
		StringBuilder result = new StringBuilder();
		for(int i=0;i<len;i++) {
			result.append(Integer.toHexString(new Random().nextInt(16)));
		}
		return result.toString().toUpperCase();
    }
}
